package com.hsjk.szwj.module.smedia.controller.admin.template;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.module.smedia.controller.admin.template.vo.TemplateMaterialsReqVO;
import com.hsjk.szwj.module.smedia.controller.admin.template.vo.TemplateMaterialsRespVO;
import com.hsjk.szwj.module.smedia.controller.admin.template.vo.TemplateParamsRespVO;
import com.hsjk.szwj.module.smedia.controller.admin.template.vo.TemplatesReqVO;
import com.hsjk.szwj.module.smedia.controller.admin.template.vo.TemplatesRespVO;
import com.hsjk.szwj.module.smedia.service.template.ITemplate;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/07/21 13:37
 **/
@Tag(name = "管理后台 - 智能媒体模板管理")
@RestController
@RequestMapping("/system/media-template")
@Validated
public class TemplateController {
    @Resource
    private ITemplate template;

    @PostMapping("/list-templates")
    @Operation(summary = "获取模板列表")
    @PreAuthorize("@ss.hasPermission('system:media-template:query')")
    public CommonResult<TemplatesRespVO> listTemplates(@Valid @RequestBody TemplatesReqVO reqVO) {
        return success(template.listTemplates(reqVO));
    }

    @PostMapping("/get-template-materials")
    @Operation(summary = "获取模板素材")
    @PreAuthorize("@ss.hasPermission('system:media-template:query')")
    public CommonResult<TemplateMaterialsRespVO> getTemplateMaterials(@Valid @RequestBody TemplateMaterialsReqVO reqVO) {
        return success(template.getTemplateMaterials(reqVO));
    }

    @GetMapping("/get-template-params")
    @Operation(summary = "获取模板素材")
    @PreAuthorize("@ss.hasPermission('system:media-template:query')")
    public CommonResult<TemplateParamsRespVO> getTemplateParams(String templateId) {
        return success(template.getTemplateParams(templateId));
    }
}
